<!--
 * @Author: thats-all-right-ha-ha 8280209+thats-all-right-ha-ha@user.noreply.gitee.com
 * @Date: 2024-02-18 11:57:01
 * @LastEditors: thats-all-right-ha-ha 8280209+thats-all-right-ha-ha@user.noreply.gitee.com
 * @LastEditTime: 2024-02-18 17:12:56
 * @FilePath: \数据筛选\index.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        /*
        筛选 16 世纪出生的发明家
        展示他们的姓和名
        把他们按照出生日期从大到小进行排序
        计算所有的发明家加起来一共活了多少岁
        按照他们活了多久来进行排序
        筛选出一个网页里含有某个词语的标题
        按照姓氏来进行排序
        统计给出数组中各个物品的数量*/

        const inventors = [
            { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
            { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
            { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
            { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
            { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
            { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
            { first: 'Max', last: 'Planck', year: 1858, passed: 1947 },
            { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },
            { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },
            { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },
            { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },
            { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 }
        ];

        const people = [
            'Bernhard, Sandra', 'Bethea, Erin', 'Becker, Carl', 'Bentsen, Lloyd', 'Beckett, Samuel', 'Blake, William', 'Berger, Ric', 'Beddoes, Mick', 'Beethoven, Ludwig',
            'Belloc, Hilaire', 'Begin, Menachem', 'Bellow, Saul', 'Benchley, Robert', 'Blair, Robert', 'Benenson, Peter', 'Benjamin, Walter', 'Berlin, Irving',
            'Benn, Tony', 'Benson, Leana', 'Bent, Silas', 'Berle, Milton', 'Berry, Halle', 'Biko, Steve', 'Beck, Glenn', 'Bergman, Ingmar', 'Black, Elk', 'Berio, Luciano',
            'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose',
            'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank'
        ];

        const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck'];

        // 1.筛选 16 世纪出生的发明家
        console.table(inventors.filter((item) => {
            return item.year > 1501 && item.year < 1600
        }))

        //2.展示他们的姓和名
        console.log(inventors.map((item) => {
            return `${item.first} ${item.last}`
        }))

        //3.把他们按照出生日期从大到小进行排序
        console.log(inventors.toSorted((a, b) => {
            return a.year - b.year
        }))

        //4.计算所有的发明家加起来一共活了多少岁
        console.log(inventors.reduce((acc, curr) => {
            return curr.passed - curr.year + acc
        }, 0))

        //5.按照他们活了多久来进行排序
        console.log(inventors.toSorted((a, b) => {
            const aYear = a.passed - a.year
            const bYear = b.passed - b.year
            return bYear - aYear
        }))

        //6.筛选出一个网页里含有某个词语的标题
        // const list = Array.from(document.querySelectorAll('.title a'))
        // const a = list.map((item) => {
        //     return item.textContent
        // }).filter(item => item.includes('东北话'))

        //按照姓氏来进行排序
        console.log(people.sort((a,b) => {
            return a.split(',')[1] > b.split(',')[1] ? 1 : -1
        }))

        console.log(people.map(item => {
            return item.split(',')
        }))

       console.log(data.reduce((acc,curr) => {
            if(!acc[curr]){
                acc[curr] = 0
            }
            acc[curr]++
            return acc
       },{}))
    </script>
</body>

</html>